<template>
  <div class="level-selector">
    <h2 class="title">选择关卡</h2>
    <div class="levels-container">
      <button 
        v-for="level in levels" 
        :key="level" 
        class="level-button" 
        :class="{ 'locked': level > unlockedLevels }"
        @click="handleClick(level)"
        :disabled="level > unlockedLevels"
      >
        <span class="level-number">{{ level }}</span>
        <span class="level-status" v-if="level > unlockedLevels">锁定</span>
      </button>
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import router from '@/router'

// 假设用户已解锁前3个关卡
const unlockedLevels = ref(3)
const levels = [1, 2, 3, 4]

const handleClick = (level) => {
  if (level <= unlockedLevels.value) {
    router.push('/' + level)
  }
}
</script>

<style scoped>
.level-selector {
  text-align: center;
  padding: 20px;
  width: 100%;
  max-width: 600px;
  margin: 0 auto;
}

.title {
  color: #333;
  font-size: 2.5rem;
  margin-bottom: 2rem;
  font-weight: 600;
  text-shadow: 2px 2px 4px rgba(118, 171, 106, 0.2);
}

.levels-container {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 20px;
  margin-top: 20px;
}

.level-button {
  position: relative;
  background: white;
  border: 3px solid #76ab6a;
  border-radius: 16px;
  padding: 20px;
  font-size: 1.8rem;
  font-weight: bold;
  color: #76ab6a;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: 0 4px 15px rgba(118, 171, 106, 0.2);
  aspect-ratio: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  backdrop-filter: blur(4px);
}

.level-button:hover:not(.locked) {
  transform: translateY(-5px);
  box-shadow: 0 8px 25px rgba(118, 171, 106, 0.3);
  background: rgba(255, 255, 255, 0.95);
}

.level-button:active:not(.locked) {
  transform: translateY(-2px);
}

.level-button.locked {
  opacity: 0.6;
  cursor: not-allowed;
  background: rgba(255, 255, 255, 0.7);
}

.level-number {
  font-size: 2.5rem;
  transition: all 0.3s ease;
}

.level-status {
  font-size: 0.9rem;
  color: #999;
  margin-top: 5px;
}

/* 响应式设计 */
@media (max-width: 480px) {
  .title {
    font-size: 2rem;
  }
  
  .level-button {
    padding: 15px;
    font-size: 1.5rem;
  }
  
  .level-number {
    font-size: 2rem;
  }
}

/* 添加你已有的动画类 */
.level-button.v-enter-active,
.level-button.v-leave-active {
  transition: opacity 0.3s, transform 0.5s;
}

.level-button.v-enter-from,
.level-button.v-leave-to {
  opacity: 0;
  transform: translateY(20px);
}
</style>